import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class NativeChannelTestPage extends StatefulWidget {
  @override
  _NativeChannelTestPageState createState() => _NativeChannelTestPageState();
}

class _NativeChannelTestPageState extends State<NativeChannelTestPage> {
  MethodChannel _methodChannel;

  @override
  void initState() {
    _methodChannel = const MethodChannel("top.tupobi.demo/channel_connection");
    _methodChannel.setMethodCallHandler((handler) {
      switch (handler.method) {
        case "flutterFunction":
          print("native invoke dart function message = ${handler.arguments["message"]}");
          break;
      }
      return null;
    });

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Native Channel"),
      ),
      body: Column(
        children: <Widget>[
          FlatButton(
            child: Text("调用native吐司"),
            onPressed: () {
              _methodChannel.invokeMethod("nativeToast", {"message": "flutter"});
            },
          )
        ],
      ),
    );
  }
}
